<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
	<title>WithDrawal Form</title>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="css/withdrawal.css" type="text/css" media="all" />
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript">
$(document).ready(function() {
   $.ajax({
			url : './user/getBrokerDetail',
			dataType: "json",
			contentType: 'application/json',			    
			success : function(jsonData) {	
					for(var a in jsonData){
					document.getElementById("bname").value=jsonData[a]["bname"];
					document.getElementById("accno").value=jsonData[a]["accno"];
					document.getElementById("emailid").value=jsonData[a]["emailID"];
					document.getElementById("fname").value=jsonData[a]["fname"]+" "+jsonData[a]["lname"];
					
				}
			}
		}); 
   
   $('#userId').change(function(event) {  
	     var $userId=$("select#userId").val();
	        $.get('./user/getUserDetail',{userName:$userId},function(jsonData) { 
	        	for(var a in jsonData){
					document.getElementById("bname").value=jsonData[a]["bname"];
					document.getElementById("accno").value=jsonData[a]["accno"];
					document.getElementById("emailid").value=jsonData[a]["emailID"];
					document.getElementById("fname").value=jsonData[a]["fname"]+" "+jsonData[a]["lname"];
					
					
				}
	        });
	        });
   $("#send").click(function(event) { 
		
		var req=0;

		 if(document.getElementById('pnameErrorLable').innerHTML!=""){
			req=1;
		}
		 else if(document.getElementById('ifscErrorLable').innerHTML!=" "){
			 req=1;
			}
		 else if(document.getElementById('bnameErrorLable').innerHTML!=""){
				req=1;
			}
		 
		 else if(document.getElementById('accnoErrorLable').innerHTML!=""){
				req=1;
			}
		 else if(document.getElementById('umailErrorLable').innerHTML!=""){
				req=1;
			}
		
		 if(req==0){		
	var reqUrl="./bank/withdrawal";
	var buyJson=JSON.stringify({"fname":$("#fname").val(),"emailid":$("#emailid").val(),"ifsc":$("#ifsc").val(),"accno":$("#accno").val(),"bname":$("#bname").val(),"w_mode":$("#w_mode").val(),"amount":$("#amount").val(),"comments":$("#comments").val(),"user_Id":$("#userId").val()});
	
	$.ajax(
		  {
		  type: "POST",
		  url: reqUrl,
		  dataType: "json",
		  contentType: 'application/json',
		  data:buyJson ,
		  success: function(html) { 			 
		    alert(html);
		  }
		  
		});
	event.preventDefaults();
	
		}
	});
});  



function formvalidation(){
	var error	=	false;
			 if((document.getElementById('emailid').value)==''){
			document.getElementById('umailErrorLable').innerHTML='*Enter  E-mail id.';
			error	=	true;
		}
			if((document.getElementById('fname').value)==''){
			document.getElementById('pnameErrorLable').innerHTML='*Enter First name.';
			error	=	true;
		}
			
			if((document.getElementById('ifsc').value)==''){
				document.getElementById('ifscErrorLable').innerHTML='*Enter IFSC Code.';
				error	=	true;
			}
			if((document.getElementById('accno').value)==''){
				document.getElementById('accnoErrorLable').innerHTML='*Enter Account Number.';
				error	=	true;
			}
			if((document.getElementById('bname').value)==''){
				document.getElementById('bnameErrorLable').innerHTML='*Enter  Bank Name.';
				error	=	true;
			}
			if((document.getElementById('amount').value)==''){
				document.getElementById('amountErrorLable').innerHTML='*Enter Amount.';
				error	=	true;
			}
		
		if(error==false){
			return true;
			}else{ 
			return false;
		}
}

function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
</script>

<script type="text/javascript">
 window.onload=$(document).ready(function() {  	
		$.get('./userList',function(responseJson) {
		
			var select = document.getElementById("userId");
			var option = document.createElement("option");
			select.appendChild(option);
	            if(responseJson!=null){      	
	                 for(var i=0; i<responseJson.length; i++ ){  
	     
			            			var option = document.createElement("option");
			            			option.value =responseJson[i]['user_ID'] ;
			            	        option.textContent = responseJson[i]['user_ID'];
			            		     select.appendChild(option);
						  }
	            } 
	      });
   	});
</script>
 
</head>
 
<body>
<div><img src="img/ncmx-logo1.png" style="width:150px;height:60px;"></img></div>
	<h2>Withdrawal Form</h2>
    <p>To withdraw funds from your account, please complete and submit the form below.<br/>

A withdrawal request will be processed only if you have sufficient available funds. If you traded today, the funds will not be available to withdrawal until the following business day.<br/>

Please note: In accordance with anti-money laundering regulations, all withdrawals will be sent from the name on the account.</p>

	
	<form class="form" method="post" id="withdrawal">
		
		<div class="name" id="field1">
        
        	<div class="field2">
			<label for="name" class="label-field">BrokerID</label>
			<span><sec:authentication property="principal.username"/></span> 
            </div>
            
            <div class="field2">
			<label for="name" class="label-field1">Client ID</label> 
			<select id="userId" name="userId"></select>
            </div>
            
		</div>
		<div class="web" id="field1">
        <div class="field2">
			<label for="name" class="label-field">Client Name<b><font color="red" size="3">*</font></b></label> <input type="text" name="fname" id="fname" placeholder="Enter your last name" />
            <div id="pnameErrorLable" style="text-align: right;"></div></div>
        	<div class="field2">
			<label for="name" class="label-field1">Email<b><font color="red" size="3">*</font></b></label> <input type="text" name="emailid" id="emailid" placeholder="mail@example.com" />
            <div id="umailErrorLable" style="text-align: right;"></div></div>
             
           
		</div>
			<div class="name" id="field1">
		<div class="field2">
			<label for="name" class="label-field">IFSC CODE<b><font color="red" size="3">*</font></b></label> <input type="text" name="ifsc" id="ifsc" placeholder="Enter IFSC Code" onkeypress="return isNumberKey(event)"/>
           <div id="ifscErrorLable" style="text-align: right;"></div> </div>
           <div class="field2">
           <label for="name" class="label-field1">Withdrawal Method<b><font color="red" size="3">*</font></b></label>
           <select id="w_mode" onchange="" style="margin-left:0;margin-right:5px;width:225px;border:1px solid #D6D8DA; height:30px; padding:5px; font-size:12px; color:#333333;" name="idproof">
	                       <!--  <option value="" selected="selected">--Select Withdrawal Mode--</option> -->
	                        <option value="Check">Check (sent to address on file)</option>
	                      <!--   <option value="Wire">Wire</option> -->
	                        
	                   </select>     
		</div>
		</div>
		
		
		<div class="web" id="field1">
		
        	<div class="field2">
				<label for="web" class="label-field">Bank Account Number<b><font color="red" size="3">*</font></b></label> 
				<input type="text" name="accno" id="accno" placeholder="Your account number" onkeypress="return isNumberKey(event)" />
			<div id="accnoErrorLable" style="text-align: right;"></div></div>
            
            <div class="field2">
				<label for="email" class="label-field1">Bank Name<b><font color="red" size="3">*</font></b></label>
                	<input type="text" name="bname" id="bname" placeholder="Your Bank Name"  />
			<div id="bnameErrorLable" style="text-align: right;"></div></div>
		</div>	
        
        <div class="web" id="field1">
        	<div class="field2">
				<label for="web" class="label-field">Amount<b><font color="red" size="3">*</font></b></label>
		<input type="text" name="amount" id="amount" placeholder="Enter Amount"  onkeypress="return isNumberKey(event)"/>
		<div id="amountErrorLable" style="text-align: right;"></div>
			</div>
            
            <div class="field2">
				<label for="email" class="label-field1">Currency</label>
				<select name="currency" class="select" id="currency">
                	 <option>NPR</option>  
               </select>
			</div>
		</div>	
        
    
		 <!-- <div class="web" id="field1">
				<label for="email" class="label-field">Withdrawal Method</label> 
				<select id="w_mode" onchange="" style="margin-left:0;margin-right:5px;width:225px;border:1px solid #D6D8DA; height:30px; padding:5px; font-size:12px; color:#333333;" name="idproof">
	                        <option value="" selected="selected">--Select Withdrawal Mode--</option>
	                        <option value="Check">Check (sent to address on file)</option>
	                        <option value="Wire">Wire</option>
	                        
	                   </select>
			</div> -->
	
		<div class="text" id="field1">
			<label for="email" class="label-field">Additional Comments </label>
			<textarea name="text" placeholder="Write something to us" id="comments"></textarea>
		</div>
		
		<div class="submit" id="field1" style="margin-left:185px;">
			<input type="button" value="Send" id="send" name="send" onclick="formvalidation();"/>
			<input type="button" value="Close" onclick="window.close()"/>
		</div>
	</form>

</body>

</html>
